//
//  EFAPjtDetailVC.m
//  efairy
//
//  Created by XiangDongMBP on 2017/8/12.
//  Copyright © 2017年 East. All rights reserved.
//

#import "EFAPjtDetailVC.h"
#import <MJRefresh.h>
#import <UIScrollView+EmptyDataSet.h>
#import "ApiManager.h"
#import "EFAModel.h"
#import "UIColor+XDHex.h"
#import "GlobalHeader.h"
#import "EFAPjtDetailHView.h"
#import "EFAPjtDetailFView.h"
#import "EFAPjtDetailTCell.h"
#import "EFAPjtAddVC.h"
#import "EFAPjtDeviceListVC.h"
#import "EFAPjtUserListVC.h"
#import "EFAPjtDeviceAddVC.h"
#import "EFAPjtUserAddVC.h"

@interface EFAPjtDetailVC ()<UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetDelegate, DZNEmptyDataSetSource, EFAPjtDetailHViewDelegate, EFAPjtDetailFViewDelegate>
@property (weak,   nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) MJRefreshNormalHeader *mj_header;
//@property (strong, nonatomic) MJRefreshAutoNormalFooter *mj_footer;
//@property (strong, nonatomic) UIBarButtonItem *saveBarBtnItem;
@property (nonatomic, strong) NSArray<NSString *> *sectionTitleArray;
@property (nonatomic, strong) NSArray<NSString *> *btnTitleArray;
@property (nonatomic, strong) EFAPjtDetailModel *pjtDetail;
@end

static NSString *const kHeaderViewId = @"EFAPjtDetailHView";
static NSString *const kFooterViewId = @"EFAPjtDetailFView";
static NSString *const kReuseCellId = @"EFAPjtDetailTCell";
static NSInteger const kRequestSize = 20;
static NSInteger const kViewFolderSize = 6;     //!< 大于6个默认就是折叠显示

@implementation EFAPjtDetailVC

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initNavigationBar];
    [self initSubViews];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 刷新一下界面
    [self refreshWholeView];
}

- (void)initNavigationBar {
    self.navigationItem.title = @"项目详情";
//    self.navigationItem.rightBarButtonItem = self.saveBarBtnItem;
//    [self.saveBarBtnItem setEnabled:NO];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}

- (void)initSubViews {
    UINib *headerNib = [UINib nibWithNibName:kHeaderViewId bundle:nil];
    [self.tableView registerNib:headerNib forHeaderFooterViewReuseIdentifier:kHeaderViewId];
    UINib *footerNib = [UINib nibWithNibName:kFooterViewId bundle:nil];
    [self.tableView registerNib:footerNib forHeaderFooterViewReuseIdentifier:kFooterViewId];
    UINib *nib = [UINib nibWithNibName:kReuseCellId bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:kReuseCellId];
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 67.0;
    self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedSectionHeaderHeight = 60.0;
//    self.tableView.sectionFooterHeight = UITableViewAutomaticDimension;
//    self.tableView.estimatedSectionFooterHeight = 22.0;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //    self.tableView.emptyDataSetDelegate = self;
    //    self.tableView.emptyDataSetSource = self;
    // 下拉刷新
    self.tableView.mj_header = self.mj_header;
    //    self.tableView.mj_footer = self.mj_footer;
    
    [self.tableView.mj_header beginRefreshing];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - DZNEmptyDataSetSource
- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:14.0]};
    return [[NSAttributedString alloc] initWithString:@"当前没有项目" attributes:dic];
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    //    return [KABDefaultVarModel sharedInstance].bitmapDefaultImg;
    return nil;
}

//- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
//    return -100.0;
//}
#pragma mark - DZNEmptyDataSetDelegate
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return YES;
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.sectionTitleArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray<NSNumber *> *rowsArray = @[@(0),
                                       @(self.pjtDetail.project_info.efairyproject_total_gms),
                                       @(self.pjtDetail.project_info.efairyproject_total_devices),
                                       @(self.pjtDetail.project_info.efairyproject_total_users)];
    NSArray<NSNumber *> *actualArray = @[@(0),
                                         @(self.pjtDetail.gm_list.count),
                                         @(self.pjtDetail.device_list.count),
                                         @(self.pjtDetail.user_list.count)];
    NSArray<NSNumber *> *unfolderArray = @[@(NO),
                                           @(self.pjtDetail.gm_list_unfolder),
                                           @(self.pjtDetail.device_list_unfolder),
                                           @(self.pjtDetail.user_list_unfolder)];
    if (section == 0) {
        return self.pjtDetail ? 5 : 0;
    } else if (section < rowsArray.count) {
        NSInteger totalRows = [rowsArray[section] integerValue];
        NSInteger actual = [actualArray[section] integerValue];
        BOOL unfolder = [unfolderArray[section] boolValue];
        if (actual < totalRows) {
            return actual;
        } else {
            return unfolder ? actual : MIN(kViewFolderSize, actual);
        }
    }
    
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    EFAPjtDetailTCell *cell = [tableView dequeueReusableCellWithIdentifier:kReuseCellId forIndexPath:indexPath];
    if (indexPath.section == 0) {
        [cell configViewWithPjtListItem:self.pjtDetail.project_info indexPath:indexPath];
    } else if (indexPath.section == 1) {    //!< 管理员列表
        if (indexPath.row < self.pjtDetail.gm_list.count) {
            NSInteger curUserId = [EFAModel sharedInstance].loginInfo.user_info.efairyuser_id;
            BOOL hide = (self.pjtDetail.project_info.efairyproject_creator_id != curUserId);
            [cell configViewWithGMItem:self.pjtDetail.gm_list[indexPath.row] hidePhone:hide];
        }
    } else if (indexPath.section == 2) {    //!< 设备列表
        if (indexPath.row < self.pjtDetail.device_list.count) {
            [cell configViewWithDeviceItem:self.pjtDetail.device_list[indexPath.row]];
        }
    } else if (indexPath.section == 3) {    //!< 用户列表
        if (indexPath.row < self.pjtDetail.user_list.count) {
            [cell configViewWithUserItem:self.pjtDetail.user_list[indexPath.row]];
        }
    }
    return cell;
}

#pragma mark - UITableViewDelegate
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//    return 14.9;
//}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    NSArray *totalArray = @[@(0),
                            @(self.pjtDetail.project_info.efairyproject_total_gms),
                            @(self.pjtDetail.project_info.efairyproject_total_devices),
                            @(self.pjtDetail.project_info.efairyproject_total_users)];
    NSArray<NSNumber *> *actualArray = @[@(0),
                                         @(self.pjtDetail.gm_list.count),
                                         @(self.pjtDetail.device_list.count),
                                         @(self.pjtDetail.user_list.count)];
    if (section < totalArray.count) {
        NSInteger totals = [totalArray[section] integerValue];
        if (totals > kViewFolderSize) {
            return 23;
        } else {
            NSInteger actual = [actualArray[section] integerValue];
            return (actual < totals) ? 23 : 0.1;
        }
    }
    return 0.1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    EFAPjtDetailHView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kHeaderViewId];
    NSString *title = nil;
    NSString *btnTitle = nil;
    NSArray *array = @[@(0),
                       @(self.pjtDetail.project_info.efairyproject_total_gms),
                       @(self.pjtDetail.project_info.efairyproject_total_devices),
                       @(self.pjtDetail.project_info.efairyproject_total_users)];
    NSInteger curUserId = [EFAModel sharedInstance].loginInfo.user_info.efairyuser_id;
    BOOL isNormalUser = ([EFAModel sharedInstance].loginInfo.user_info.efairyrole_level == EFALoginUserRoleNormal);
    NSArray *hiddrenArray = @[@(self.pjtDetail.project_info.efairyproject_creator_id != curUserId),
                              @(self.pjtDetail.project_info.efairyproject_creator_id != curUserId),
                              @(isNormalUser),
                              @(isNormalUser)];
    if (section < self.sectionTitleArray.count) {
        title = self.sectionTitleArray[section];
        btnTitle = self.btnTitleArray[section];
        if (section > 0 && section < array.count) {
            title = [NSString stringWithFormat:@"%@(%@)", title, array[section]];
        }
    }
    view.titleLabel.text = title;
    view.btnTitle = btnTitle;
    if (section < hiddrenArray.count) {
        view.managerBtn.hidden = [hiddrenArray[section] boolValue];
    }
    view.section = section;
    view.delegate = self;
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    NSArray<NSNumber *> *array = @[@(0),
                                   @(self.pjtDetail.project_info.efairyproject_total_gms),
                                   @(self.pjtDetail.project_info.efairyproject_total_devices),
                                   @(self.pjtDetail.project_info.efairyproject_total_users)];
    NSArray<NSNumber *> *actualArray = @[@(0),
                                         @(self.pjtDetail.gm_list.count),
                                         @(self.pjtDetail.device_list.count),
                                         @(self.pjtDetail.user_list.count)];
    NSArray<NSNumber *> *unfolderArray = @[@(NO),
                                           @(self.pjtDetail.gm_list_unfolder),
                                           @(self.pjtDetail.device_list_unfolder),
                                           @(self.pjtDetail.user_list_unfolder)];
    if (section < array.count && section < actualArray.count) {
        NSInteger rows = [array[section] integerValue];
        NSInteger actual = [actualArray[section] integerValue];
        if ((rows > kViewFolderSize) || (rows <= kViewFolderSize && actual < rows)) {
            EFAPjtDetailFView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kFooterViewId];
            view.unfolder = (actual < rows) ? NO : [unfolderArray[section] boolValue];
            view.section = section;
            view.delegate = self;
            return view;
        }
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 2) {       //!< 设备列表
        if (indexPath.row < self.pjtDetail.device_list.count) {
            EFADeviceListItem *item = self.pjtDetail.device_list[indexPath.row];
            [self jumpToDeviceDetailWithItem:item];
        }
    } else if (indexPath.section == 3) {//!< 用户列表
        if (indexPath.row < self.pjtDetail.user_list.count) {
            NSInteger curUserId = [EFAModel sharedInstance].loginInfo.user_info.efairyuser_id;
            NSInteger creatorId = self.pjtDetail.project_info.efairyproject_creator_id;
            EFAPjtUserAddVCType viewType = (curUserId == creatorId) ? EFAPjtUserAddVCTypeUserEdit : EFAPjtUserAddVCTypeUserDetail;
            EFAPjtUserAddVC *vc = [[EFAPjtUserAddVC alloc] initWithViewType:viewType];
            vc.project_id = self.pjtDetail.project_info.efairyproject_id;
            vc.userItem = self.pjtDetail.user_list[indexPath.row];;
            [self showViewController:vc sender:nil];
        }
    }
}

#pragma mark - EFAPjtDetailHViewDelegate
- (void)pjtDetailHView:(EFAPjtDetailHView *)view section:(NSInteger)section managerBtnTapped:(UIButton *)btn {
    if (section == 0) {
        [self jumpToEditPjtInfo];
    } else if (section == 1) {
        [self jumpToEditGM];
    } else if (section == 2) {
        [self jumpToEditDevice];
    } else if (section == 3) {
        [self jumpToEditUser];
    }
}

#pragma mark - EFAPjtDetailFViewDelegate
- (void)pjtDetailFView:(EFAPjtDetailFView *)view section:(NSInteger)section moreBtnTapped:(UIButton *)btn {
    if (section == 1) {         //!< 管理员列表
        if (self.pjtDetail.gm_list.count < self.pjtDetail.project_info.efairyproject_total_gms) {
            [self requestPjtGMListWithHeader:NO];
        } else {
            self.pjtDetail.gm_list_unfolder = !self.pjtDetail.gm_list_unfolder;
            [self refreshWholeView];
        }
    } else if (section == 2) {  //!< 设备列表
        if (self.pjtDetail.device_list.count < self.pjtDetail.project_info.efairyproject_total_devices) {
            [self requestPjtDeviceListWithHeader:NO];
        } else {
            self.pjtDetail.device_list_unfolder = !self.pjtDetail.device_list_unfolder;
            [self refreshWholeView];
        }
    } else if (section == 3) {  //!< 用户列表
        if (self.pjtDetail.user_list.count < self.pjtDetail.project_info.efairyproject_total_users) {
            [self requestPjtUserListWithHeader:NO];
        } else {
            self.pjtDetail.user_list_unfolder = !self.pjtDetail.user_list_unfolder;
            [self refreshWholeView];
        }
    }
}

#pragma mark - event response


#pragma mark - private methods
- (void)jumpToEditPjtInfo {
    EFAPjtAddVC *vc = [[EFAPjtAddVC alloc] initWithViewType:EFAPjtAddVCTypeEdit];
    vc.pjtItem = self.pjtDetail.project_info;
    vc.successHandle = ^{
        [self refreshWholeView];
    };
    [self showViewController:vc sender:nil];
}
- (void)jumpToEditDevice {
    EFAPjtDeviceListVC *vc = [[EFAPjtDeviceListVC alloc] init];
//    vc.project_id = self.pjtDetail.project_info.efairyproject_id;
    vc.pjtDetail = self.pjtDetail;
    [self showViewController:vc sender:nil];
}
- (void)jumpToDeviceDetailWithItem:(EFADeviceListItem *)item {
    EFAPjtDeviceAddVC *vc = [[EFAPjtDeviceAddVC alloc] initWithViewType:EFAPjtDeviceAddVCTypeDetail];
    vc.project_id = self.pjtDetail.project_info.efairyproject_id;
    vc.deviceItem = item;
    [self showViewController:vc sender:nil];
}
- (void)jumpToEditGM {
    EFAPjtUserListVC *vc = [[EFAPjtUserListVC alloc] initWithViewType:EFAPjtUserListVCTypeGM];
    vc.pjtDetail = self.pjtDetail;
    [self showViewController:vc sender:nil];
}
- (void)jumpToEditUser {
    EFAPjtUserListVC *vc = [[EFAPjtUserListVC alloc] initWithViewType:EFAPjtUserListVCTypeUser];
    vc.pjtDetail = self.pjtDetail;
    [self showViewController:vc sender:nil];
}
- (void)refreshWholeView {
    //    // 尾部加载更多的显示
    //    if (self.userList.totalLoad) {
    //        [self.tableView.mj_footer endRefreshingWithNoMoreData];
    //    } else {
    //        [self.tableView.mj_footer resetNoMoreData];
    //    }
    
//    self.saveBarBtnItem.enabled = [self checkSaveBtnState];
    [self.tableView reloadData];
}

- (void)tableViewEndRefresh:(BOOL)isHeader {
    NSLog(@"停止刷新是否是头部---%zd", isHeader);
    if (isHeader) {
        [self.tableView.mj_header endRefreshing];
    } else {
        [self.tableView.mj_footer endRefreshing];
    }
}

- (void)tableViewRefresh:(id)sender {
    BOOL isHeader = [sender isKindOfClass:[MJRefreshHeader class]];
    [self requestProjectDetailWithHeader:isHeader];
}
#pragma mark - network request
- (void)requestProjectDetailWithHeader:(BOOL)isHeader {
    // 发布Cos需要登录
    if (![EFAModel sharedInstance].isLogin) {
        [self tableViewEndRefresh:isHeader];
        return;
    }
    
    NSMutableDictionary *pars = [NSMutableDictionary dictionary];
    [pars setObject:@([EFAModel sharedInstance].loginInfo.user_info.efairyuser_id) forKey:@"efairyuser_id"];
    [pars setObject:[EFAModel sharedInstance].loginInfo.access_token forKey:@"access_token"];
    [pars setObject:@(self.project_id) forKey:@"efairyproject_id"];
    NSLog(@"项目详情的参数 = %@", pars);
    
    [[XDAFNetworking sharedInstance] GET:[ApiManager apiPjtManager] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"项目详情返回：%@", responseObject);
        [self tableViewEndRefresh:isHeader];
        self.pjtDetail = [EFAPjtDetailModel yy_modelWithDictionary:responseObject[EFAGlobalJsonKeyResult]];
        [self refreshWholeView];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"项目详情失败：%@", error);
        [self tableViewEndRefresh:isHeader];
        NSString *msg = [[ApiErrorCode sharedInstance] errorCodeMsgWithError:error];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:msg];
    }];
}

- (void)requestPjtGMListWithHeader:(BOOL)isHeader {
    // 发布Cos需要登录
    if (![EFAModel sharedInstance].isLogin) {
        return;
    }
    
    NSInteger last_id = isHeader ? 0 : self.pjtDetail.gm_list.lastObject.efairyuser_id;
    NSDictionary *pars = @{@"efairyuser_id" : @([EFAModel sharedInstance].loginInfo.user_info.efairyuser_id),
                           @"access_token" : [EFAModel sharedInstance].loginInfo.access_token,
                           @"efairyproject_id" : @(self.project_id),
                           //                           @"keyword" : @"",
                           @"last_id" : @(last_id),
                           @"size" : @(kRequestSize)};
    MBProgressHUD *hud = [MBProgressHUD xd_showHUDAddedTo:self.view animated:YES];
    [[XDAFNetworking sharedInstance] GET:[ApiManager apiPjtMgrGMList] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"请求设备列表返回：%@", responseObject);
        [hud hideAnimated:YES];
        [self.pjtDetail addMoreGMWithDictionary:responseObject];
        [self refreshWholeView];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请求设备列表失败：%@", error);
        [hud hideAnimated:NO];
        NSString *msg = [[ApiErrorCode sharedInstance] errorCodeMsgWithError:error];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:msg];
    }];
}

- (void)requestPjtDeviceListWithHeader:(BOOL)isHeader {
    // 发布Cos需要登录
    if (![EFAModel sharedInstance].isLogin) {
        [self tableViewEndRefresh:isHeader];
        return;
    }
    
    NSInteger last_id = isHeader ? 0 : self.pjtDetail.device_list.lastObject.efairydevice_id;
    NSDictionary *pars = @{@"efairyuser_id" : @([EFAModel sharedInstance].loginInfo.user_info.efairyuser_id),
                           @"access_token" : [EFAModel sharedInstance].loginInfo.access_token,
                           @"efairyproject_id" : @(self.project_id),
                           //                           @"keyword" : @"",
                           @"last_id" : @(last_id),
                           @"size" : @(kRequestSize)};
    
    MBProgressHUD *hud = [MBProgressHUD xd_showHUDAddedTo:self.view animated:YES];
    [[XDAFNetworking sharedInstance] GET:[ApiManager apiPjtMgrDevList] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"请求设备列表返回：%@", responseObject);
        [hud hideAnimated:YES];
        [self.pjtDetail addMoreDeviceWithDictionary:responseObject];
        [self refreshWholeView];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请求设备列表失败：%@", error);
        [hud hideAnimated:NO];
        NSString *msg = [[ApiErrorCode sharedInstance] errorCodeMsgWithError:error];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:msg];
    }];
}

- (void)requestPjtUserListWithHeader:(BOOL)isHeader {
    // 发布Cos需要登录
    if (![EFAModel sharedInstance].isLogin) {
        return;
    }
    
    NSInteger last_id = isHeader ? 0 : self.pjtDetail.user_list.lastObject.efairyuser_id;
    NSDictionary *pars = @{@"efairyuser_id" : @([EFAModel sharedInstance].loginInfo.user_info.efairyuser_id),
                           @"access_token" : [EFAModel sharedInstance].loginInfo.access_token,
                           @"efairyproject_id" : @(self.project_id),
                           //                           @"keyword" : @"",
                           @"last_id" : @(last_id),
                           @"size" : @(kRequestSize)};
    
    MBProgressHUD *hud = [MBProgressHUD xd_showHUDAddedTo:self.view animated:YES];
    [[XDAFNetworking sharedInstance] GET:[ApiManager apiPjtMgrUserList] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"请求设备列表返回：%@", responseObject);
        [hud hideAnimated:YES];
        [self.pjtDetail addMoreUserWithDictionary:responseObject];
        [self refreshWholeView];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请求设备列表失败：%@", error);
        [hud hideAnimated:NO];
        NSString *msg = [[ApiErrorCode sharedInstance] errorCodeMsgWithError:error];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:msg];
    }];
}

#pragma mark - getters and setters
//- (UIBarButtonItem *)saveBarBtnItem {
//    if (!_saveBarBtnItem) {
//        _saveBarBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(addBarBtnTapped:)];
//        NSDictionary * barItemAttributes = @{NSForegroundColorAttributeName: [UIColor xd_colorWithHex:EFAGlobalColorDarkGreen],
//                                             NSFontAttributeName: [UIFont systemFontOfSize:15]};
//        [_saveBarBtnItem setTitleTextAttributes:barItemAttributes forState:UIControlStateNormal];
//        NSDictionary * disableBarItemAtt = @{NSForegroundColorAttributeName: [UIColor xd_colorWithHex:EFAGlobalColorDarkGreen alpha:0.5],
//                                             NSFontAttributeName: [UIFont systemFontOfSize:15]};
//        [_saveBarBtnItem setTitleTextAttributes:disableBarItemAtt forState:UIControlStateDisabled];
//    }
//    return _saveBarBtnItem;
//}
- (NSArray<NSString *> *)btnTitleArray {
    if (!_btnTitleArray) {
        _btnTitleArray = @[@"管理", @"管理", @"管理", @"    用户管理&设备分配    "];
    }
    return _btnTitleArray;
}
- (NSArray<NSString *> *)sectionTitleArray {
    if (!_sectionTitleArray) {
        _sectionTitleArray = @[@"项目信息", @"管理员列表", @"设备列表", @"用户列表"];
    }
    return _sectionTitleArray;
}

- (MJRefreshNormalHeader *)mj_header {
    if (!_mj_header) {
        _mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(tableViewRefresh:)];
        _mj_header.lastUpdatedTimeLabel.hidden = YES;
    }
    return _mj_header;
}

- (EFAProjectModel *)projectModel {
    return [EFAModel sharedInstance].projectModel;
}

@end
